{extend name="template/base" /}
{block name="content"}
<!--select2样式 start -->
<link href="__LIB__/select2-4.0.3/dist/css/select2.min.css" rel="stylesheet" />
<div class="page-container">
    <style>
        table,table tr th, table tr td { border:1px solid #000; }
    </style>
    {include file="form" /}
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            {tp:menu menu="delete,recyclebin" /}
            <a class="btn btn-primary radius mr-5" id="sou" href="{:url('/admin/collect_data/export_to_excel',$searchCondition)}" >excel导出</a>
            <a class="btn btn-primary radius mr-5" id="xuan" style="display: none;"  href="javascript:;" onclick="xuan()">excel导出</a>
        </span>
        <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
    </div>
    {php} use think\Db;{/php}
    <table class="table table-border table-bordered table-hover table-bg mt-20">
        <thead>
        <tr class="text-c">
            {include file="th" /}
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr class="text-c">
            {include file="td" /}
            <td class="f-14">
                {if ($vo['settlement_status'] == 1)}
                    <a title="申请结算" href="javascript:;" onclick="applySettlement({$vo.id})" style="text-decoration:none;" class="ml-5 label label-warning radius">申请结算</a>
                {elseif ($vo['settlement_status'] == 2)}
                    <a title="结算按钮" href="javascript:;" onclick="settlement({$vo.id})" style="text-decoration:none;" class="ml-5 label label-warning radius">结算</a>
                {elseif ($vo['settlement_status'] == 3)}
                    <a title="未结算" href="javascript:;" onclick="noSettlement({$vo.id})" style="text-decoration:none;" class="ml-5 label label-warning radius">未结算</a>
                {/if}

                <a title="酒店房价" href="javascript:;" onclick="layer_open('酒店房价列表','/admin/collect_data/priceList/id/{$vo.id}')" style="text-decoration:none;display: none" class="ml-5 label label-warning radius">酒店房价列表</a>
                {tp:menu menu='sedit' /}
                {tp:menu menu='sdelete' /}
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page-bootstrap">{$page ?? ''}</div>
</div>
{/block}

{block name="script"}
<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<!--select2 js 插件-->
<script type="text/javascript" src="__LIB__/select2-4.0.3/dist/js/select2.min.js"></script>

<script>

    //全选
    $('#checkAlls').bind("click", function () {
        $("input[name='id[]']").prop("checked",this.checked);
        var sonChecked = $("input[name='id[]']").prop('checked');
        var allChecked = this.checked
        if (sonChecked && allChecked){
            $('#xuan').css('display','inline') // 显示选择excel导出数据
            $('#sou').css('display','none') // 隐藏部分或全部excel导出数据
        }else{
            $('#xuan').css('display','none')
            $('#sou').css('display','inline')
        }
        // console.log('你点击我了')
        // console.log('你是否被选中', this.checked)
        // console.log('下级的选框', $("input[name='id[]']").prop('checked'))
    });

    // 单选
    $("input[name='id[]']").bind('click', function () {
        var radioData =  $("input:checked[name='id[]']");
        // 选择数据的长度
        var len = radioData.serializeArray().length;
        if (len > 0) {
            $('#xuan').css('display','inline') // 显示选择excel导出数据
            $('#sou').css('display','none') // 隐藏部分或全部excel导出数据
        } else {
            $('#xuan').css('display','none')
            $('#sou').css('display','inline')
            $('#checkAlls').prop('checked',false); // 取消选择全选按钮
        }
        // console.log('你点击了单选')
        // console.log('点击的结果为：', this.checked)
        // console.log('你选择的数据是', radioData.serializeArray())
        // console.log('你选择的数据长度是',len)
    });

    function xuan() {
        var checkData = $("input:checked[name='id[]']");
        var dataArr = checkData.serializeArray();
        dataArr.push({name: 'search',value: 'all'})
        $.ajax({
            type: 'post',
            url: '/admin/collect_data/export_to_excel',
            data: dataArr,
            success: function (res) {
                if (res.code == 5){
                    // console.log('data', res);
                    location.href = res.msg; // 下载文件
                    // 删除文件
                    unclinkFile(res.msg)
                    layer.msg('导出数据成功');
                } else {
                    layer_open('excel导出数据','/admin/pub/role/id/1')
                }
            }
        });
    }
    var  value = 1;
    setTimeout(unclinkFile,1200000,value); // 延迟20分钟1200000
    // 15分钟后删除文件-900000
    function unclinkFile(val) {
        console.log(val)
        setTimeout(function () {
            // 删除文件
            $.ajax({
                type: 'post',
                url: '/admin/order/del',
                data: {val:val},
                success: function (data) {
                    console.log('data', data)
                    if (data.code != 5) {
                        console.log('删除失败', data.msg)
                    }
                }
            })
        },120000,val); // 2分钟后执行
    }

</script>


<script>
    // 申请结算
    function applySettlement(id) {
        $.ajax({
            type: 'POST',
            url: '/admin/collect_data/applySettlement',
            data: {id: id},
            success: function (ret) {
                if (ret.code == 1){
                    layer.msg(ret.msg);
                    return false;
                } else {
                    layer.msg(ret.msg);
                    location.reload();
                }
            }
        });
    }

    // 已结算
    function settlement(id) {
        $.ajax({
            type: 'POST',
            url: '/admin/collect_data/settlement',
            data: {id: id},
            success: function (ret) {
                if (ret.code == 1){
                    layer.msg(ret.msg);
                    return false;
                } else {
                    layer.msg(ret.msg);
                    location.reload();
                }
            }
        });
    }

    // 未结算
    function noSettlement(id) {
        $.ajax({
            type: 'POST',
            url: '/admin/collect_data/noSettlement',
            data: {id: id},
            success: function (ret) {
                if (ret.code == 1){
                    layer.msg(ret.msg);
                    return false;
                } else {
                    layer.msg(ret.msg);
                    location.reload();
                }
            }
        });
    }
</script>
<script>

    var room_type_id = $("#room_type_id").select2({
        language: "zh-CN", //设置 提示语言
        width: "100%", //设置下拉框的宽度
        theme: "classic"
    })
    {notempty name = "Request.param.room_type_id"}
    room_type_id.val("{$Request.param.room_type_id}").trigger("change");
    {/notempty}
</script>
{/block}
